package com.esun.payment_api.service.impl;

import com.esun.payment_api.bean.InvCancelDetailBean;
import com.esun.payment_api.dao.InvCancelFormDao;
import com.esun.payment_api.domain.InvCancelForm;
import com.esun.payment_api.dto.InvCancelFormQueryParam;
import com.esun.payment_api.dto.SubmitApprovalParam;
import com.esun.payment_api.mapper.InvCancelFormMapper;
import com.esun.payment_api.service.InvCancelFormService;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("InvCancelFormService")
public class InvCancelFormServiceImpl implements InvCancelFormService {

    @Resource
    InvCancelFormMapper invCancelFormMapper;

    @Override
    public InvCancelDetailBean getInvCancelDetail(Short userId, Integer id) {
        return invCancelFormMapper.getInvCancelDetail(userId, id);
    }

    @Override
    public int deleteById(Integer id) {
        return invCancelFormMapper.deleteById(id);
    }

    @Override
    public int update(InvCancelForm record) {
        return invCancelFormMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public void invCancelSubmitApproval(SubmitApprovalParam param) {
        String flowTypeName = "";
        if ("1".equals(param.getBusinessType())) {
            flowTypeName = "发票作废申请流程";
        } else if ("2".equals(param.getBusinessType())) {
            flowTypeName = "发票作废申请流程(纵向)";
        } else if ("3".equals(param.getBusinessType())) {
            flowTypeName = "发票作废申请流程(预研)";
        } else if ("4".equals(param.getBusinessType())) {
            flowTypeName = "发票作废申请流程(版面费)";
        } else if ("5".equals(param.getBusinessType())) {
            flowTypeName = "发票作废申请流程(财务资金调拨)";
        } else if ("6".equals(param.getBusinessType())) {
            flowTypeName = "发票作废申请流程(承兑汇票到期)";
        } else if ("7".equals(param.getBusinessType())) {
            flowTypeName = "发票作废申请流程(民品(缝编))";
        } else if ("8".equals(param.getBusinessType())) {
            flowTypeName = "发票作废申请流程(其他)";
        } else if ("9".equals(param.getBusinessType())) {
            flowTypeName = "发票作废申请流程(工艺)";
        } else if ("10".equals(param.getBusinessType())) {
            flowTypeName = "发票作废申请流程(民品)";
        } else if ("11".equals(param.getBusinessType())) {
            flowTypeName = "发票作废申请流程(考试费)";
        } else if ("12".equals(param.getBusinessType())) {
            flowTypeName = "发票作废申请流程(纵向YH)";
        } else if ("13".equals(param.getBusinessType())) {
            flowTypeName = "发票作废申请流程(纵向WQ)";
        }
        invCancelFormMapper.invCancelSubmitApproval(param.getCoId(), param.getUuid(), param.getInvId(), param.getUserId(), param.getDeptId(), flowTypeName);
    }

    @Override
    public void invCancelResubmitApproval(SubmitApprovalParam param) {
        String flowTypeName = "";
        if ("1".equals(param.getBusinessType())) {
            flowTypeName = "发票作废申请流程";
        } else if ("2".equals(param.getBusinessType())) {
            flowTypeName = "发票作废申请流程(纵向)";
        } else if ("3".equals(param.getBusinessType())) {
            flowTypeName = "发票作废申请流程(预研)";
        } else if ("4".equals(param.getBusinessType())) {
            flowTypeName = "发票作废申请流程(版面费)";
        } else if ("5".equals(param.getBusinessType())) {
            flowTypeName = "发票作废申请流程(财务资金调拨)";
        } else if ("6".equals(param.getBusinessType())) {
            flowTypeName = "发票作废申请流程(承兑汇票到期)";
        } else if ("7".equals(param.getBusinessType())) {
            flowTypeName = "发票作废申请流程(民品(缝编))";
        } else if ("8".equals(param.getBusinessType())) {
            flowTypeName = "发票作废申请流程(其他)";
        } else if ("9".equals(param.getBusinessType())) {
            flowTypeName = "发票作废申请流程(工艺)";
        } else if ("10".equals(param.getBusinessType())) {
            flowTypeName = "发票作废申请流程(民品)";
        } else if ("11".equals(param.getBusinessType())) {
            flowTypeName = "发票作废申请流程(考试费)";
        } else if ("12".equals(param.getBusinessType())) {
            flowTypeName = "发票作废申请流程(纵向YH)";
        } else if ("13".equals(param.getBusinessType())) {
            flowTypeName = "发票作废申请流程(纵向WQ)";
        }
        invCancelFormMapper.invCancelResubmitApproval(param.getCoId(), param.getUuid(), param.getInvId(), param.getUserId(), param.getDeptId(), flowTypeName);
    }

    @Override
    public String checkInvCancelSubmit(Integer id) {
        return invCancelFormMapper.checkInvCancelSubmit(id);
    }

    @Override
    public int updateById(InvCancelForm record) {
        return invCancelFormMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public String getBusinessTypeByInvCancelId(SubmitApprovalParam param) {
        return invCancelFormMapper.getBusinessTypeByInvCancelId(param.getCoId(), param.getInvId());
    }

    @Override
    public List<InvCancelFormDao> getListByType(InvCancelFormQueryParam queryParam, Integer pageSize, Integer pageNum) {
        PageHelper.startPage(pageNum, pageSize);
        return invCancelFormMapper.getListByType(queryParam);
    }
}
